package Testes;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import jdbc.ConnectionFactory;

public class TestaLogin {
	
	private static Connection cnn;
	private static PreparedStatement stmt;
	private static ResultSet rs;
	private static String sql;

	public static void main(String[] args) throws SQLException {
		if (validaLogin("lala", "lala")) {
			System.out.println("Logado!!");
		}
	}

	public static boolean validaLogin(String login, String senha) throws SQLException {
		sql = "SELECT * FROM slv_web.tblogin WHERE login=? AND senha=?";
		cnn = new ConnectionFactory().getConnection();
		
		try {
			stmt = cnn.prepareStatement(sql);
			stmt.setString(1, login);
			stmt.setString(2, senha);
			rs = stmt.executeQuery();
			if (rs.next())
				return true;
			else
				return false;
		} catch (Exception e) {
			e.printStackTrace();
			try {
				cnn.rollback();
			} catch (SQLException e1) {
				System.out.print(e1.getStackTrace());
			}
			return false;
		} finally {
			stmt.close();
			cnn.close();
		} 
	}
}
